﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DAL;
namespace BLL.Admin
{
    public class DMCapBacHelper
    {
        public static void Add_DanhMucCapBac(string Ten)
        {
            var db = Connect.GetDataContext<TimViecDataContext>("Strconnect");
            db.tbl_DM_CapBacCVs.InsertOnSubmit( new tbl_DM_CapBacCV
                                                    {
                                                        Mota = Ten
                                                    });
            db.SubmitChanges();
        }
        public static void Update_DMCapBac(int CapBacId,string Ten)
        {
            var db = Connect.GetDataContext<TimViecDataContext>("Strconnect");
            var dm = db.tbl_DM_CapBacCVs.FirstOrDefault(k => k.CapBacId == CapBacId);
            if(dm !=null)
            {
                dm.Mota = Ten;
                db.SubmitChanges();
            }
        }
        public static tbl_DM_CapBacCV Get_DMCapBac(int CapBacId)
        {
            var db = Connect.GetDataContext<TimViecDataContext>("Strconnect");
            return  db.tbl_DM_CapBacCVs.FirstOrDefault(k => k.CapBacId == CapBacId);
        }
        public static IQueryable List_DMCapBac()
        {
            var db = Connect.GetDataContext<TimViecDataContext>("Strconnect");
            var query = from dmcb in db.tbl_DM_CapBacCVs
                        orderby dmcb.Mota ascending 
                        select new
                                   {
                                       dmcb.CapBacId,
                                       dmcb.Mota,
                                   };
            return query;
        }
    }
}